#include "threadPool.hpp"
#include "task.hpp"
#include <ctime>
#include <cstdlib>

// void *run(void *args)
// {
//     while(true)
//     {
//         ThreadPool<Task>::getThreadPool();
//     }
// }

int main()
{
    // logMessage(NORMAL, "%s %d %c %f\n", "日志信息", 12341, 'c', 3.1235);

    // va_list ap;
    // va_start(ap, XXX);
    // va_arg(ap, int);

    srand((unsigned int)time(nullptr) ^ getpid());
    // ThreadPool<Task> *tp = new ThreadPool<Task>();

    // ThreadPool<Task> *tp = ThreadPool<Task>::getThreadPool(5);
    // tp->run();
    ThreadPool<Task>::getThreadPool()->run();
    while (true)
    {

        // 生产任务
        int x = rand() % 100 + 1;
        usleep(1234);
        int y = rand() % 30 + 1;
        Task t(x, y, [](int x, int y) -> int
               { return x + y; });

        // cout << "任务制作完成" << endl;
        logMessage(DEBUG, "任务制作完成：%d + %d = ? ", x, y);

        // push到线程池
        // tp->pushTask(t);
        ThreadPool<Task>::getThreadPool()->pushTask(t);
        sleep(1);
    }

    return 0;
}